public class test2 {
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] dpf =new int[n];
        int[] dpg =new int[n];
        for (int i = 1; i < n; i++) {
            dpf[i] = dpf[i-1] + nums[i-1];
        }

        for (int i = n-2; i >=0; i--) {
            dpg[i] = dpg[i+1] + nums[i+1];
        }


        for(int i = 0;i<n;i++){
            if(dpf[i]==dpg[i]){
                return i;
            }
        }
        return -1;
    }
}
